package com.ruifu.bom.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.ruifu.bom.dto.StructureDTO;
import com.ruifu.bom.service.MaterielStructureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 物料结构控制层
 *
 * @author lcq
 * @create 2020/1/6
 */
@RestController
@RequestMapping("/materielStructure")
public class MaterielStructureController {
    @Autowired
    MaterielStructureService materielStructureService;

    /**
     * 新建下级件
     *
     * @param structureDTO
     * @return
     */
    @PostMapping("/subordinateSave")
    public R subordinateSave(@RequestBody StructureDTO structureDTO) {
        try {
            return R.ok(materielStructureService.save(structureDTO));
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed(e.getMessage());
        }
    }

    /**
     * bom视图查看
     * @param mvId
     * @return
     */
//    @GetMapping("/examineParts/{mvId}")
//    public R examineParts(@PathVariable("mvId") Long mvId){
//        return R.ok(materielStructureService.findById(mvId));
//    }

    /**
     * bom视图移除零部件
     */
//    @GetMapping("/removeParts/{mlId}")
//    public R removeParts(@PathVariable("mlId") Long mlId){
//        try {
//            return R.ok(materielStructureService.removeParts(mlId));
//        } catch (Exception e) {
//            e.printStackTrace();
//            return R.failed(e.getMessage());
//        }
//    }

    /**
     * 用于何处
     *
     * @param stMaterielId 子项物料id
     * @return
     */
    @GetMapping("/useWhere/{stMaterielId}")
    public R useWhere(@PathVariable("stMaterielId") Long stMaterielId) {
        return R.ok(materielStructureService.useWhere(stMaterielId));
    }


}
